﻿using CSharpOnlineMVC.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CSharpOnlineMVC.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(DB.Movies);
        }

        public ActionResult About()
        {
            Movie newMovie = new Movie()
            {
                Title = "Star Wars",
                YearReleased = 1989,
                Rating = MovieRating.PG13,
                ImageUrl = "http://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Star_Wars_Logo.svg/2000px-Star_Wars_Logo.svg.png"
            };

            return View(newMovie);
        }

        public ActionResult Details(int id)
        {
            Movie model = DB.Movies.FirstOrDefault(movie => movie.MovieId == id);
            /* Using raw c#
             * Movie model;
             *
             * foreach(Movie m in DB.Movies) {
             *      if(m.MovieId == id) {
             *          model = m;
             *          break;
             *      }
             * }
             * */

            return View(model);
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}